package com.example.provider;

import com.example.provider.constant.MqConstant;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.junit.jupiter.api.Test;

/**
 * @description: TODO
 * @author: uu
 * @date: 2023/12/9 22:42
 * @version: 1.0
 */
public class BAsyncRocketmq {
    @Test
    void producer() throws Exception{
        DefaultMQProducer producer = new DefaultMQProducer("async");
        producer.setNamesrvAddr(MqConstant.NAME_SRV_ADDR);
        producer.start();

        Message message = new Message("asyncTopic", "异步消息".getBytes());
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("发送成功");
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("发送失败: " + throwable.getMessage());
            }
        });

        System.in.read();
    }
}
